module.exports = {
  /**
   * 批量添加数据
   * @url template/db_api/pub/adds 前端调用的url参数地址
   * data 请求参数 说明
   * res 返回参数说明
   * @params {Number} code 错误码，0表示成功
   * @params {String} msg 详细信息
   */
  main: async (event) => {
		let { data = {}, userInfo, util, originalParam } = event;
		let { uniID, pubFun, vk , db, _ } = util;
		let { uid } = data;
		let res = { code : 0, msg : 'ok' };
    // 业务逻辑开始-----------------------------------------------------------
		let dbName = "uni-id-users";
		let addNum = 2000;
		for(let j=0; j<15; j++){
			let runTime1 = new Date().getTime();
			console.log(new Date(runTime1),"开始运行,添加"+addNum+"条数据");
			// 承载所有读操作的 promise 的数组
			let dataArr = [];
			for(let i = 1; i <= addNum; i++){
				let order_no = vk.pubfn.createOrderNo();
				dataArr.push(
				{
				    "account_balance": {
				        "balance": 9269160,
				        "total": 10000000,
				        "used": 730840
				    },
				    "account_integral": {
				        "balance": 0,
				        "total": 0,
				        "used": 0
				    },
				    "account_reward": {
				        "allow": 34148,
				        "success": 0,
				        "total": 0,
				        "used": 65852,
				        "wait": 0
				    },
				    "allow_login_background": true,
				    "avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/hrTPJATib69GHV3msOWvXcDtibRlgvcY5QLqBrEKXYDWwUxJjbI1xrHPAD02W0rwAylgya0rBWnGkNJG0gXSjiaew/132",
				    "birthday": {
				        "text": "2022-03-18",
				        "time": 1647532800000
				    },
				    "fx": {
				        "apply_comment": "666",
				        "invite_code": "888888",
				        "inviter_uid": "000",
				        "is_fx": 1,
				        "mobile": "15200000001",
				        "new_invite_time": 1654937054469,
				        "real_name": "VK",
				        "status": 1,
				        "status_str": "啊啊啊啊啊"
				    },
				    "gender": 0,
				    "invite_time": 1654937054469,
				    "inviter_uid": [
				        "000"
				    ],
				    "last_login_date": 1655801381983,
				    "last_login_ip": "127.0.0.1",
				    "login_ip_limit": [],
				    "my_invite_code": "999999",
				    "nickname": "VK",
				    "password": "975276e780f51ee1adb6ebf606e624cb2b6ad7ac",
				    "real_name": "VK",
				    "register_date": 1596416400000,
				    "register_ip": "127.0.0.1",
				    "role": [
				        "admin"
				    ],
				    "social_info": {
				        "mobile": "15200000001",
				        "weixin_no": "666",
				        "weixin_qrcode": "https://7463-tcb-b9z9ldh0uxadc9l81780b-c86eb4-1302380605.tcb.qcloud.la/2022/06/17/33651175-15811473-0.png"
				    },
				    "status": 0,
				    "vip_code": {
				        "code": "116549292543524492",
				        "exp_time": 1654929344352
				    },
				    "vip": {
				        "exp_time": 0,
				        "get_time": 1596416400000,
				        "lv": 2,
				        "name": "VIP2"
				    }
				});

			}
			await vk.baseDao.adds({
				dbName:dbName,
				dataJson:dataArr
			});

			let runTime2 = new Date().getTime();
			let runTime = ((runTime2 - runTime1) / 1000 + "秒");
			console.log(new Date(runTime2),"运行结束,耗时:"+runTime);
			res.runTime = runTime;
		}

    // 业务逻辑结束-----------------------------------------------------------
    return res;
  }
}
